package com.zhipu.resetbalance.utils.popup;

import android.content.Context;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ThreadUtils;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupAnimation;
import com.zhipu.resetbalance.mobile.temporaryClass.VersionUpdate;
import com.zhipu.resetbalance.pop.BeCommonPopup;
import com.zhipu.resetbalance.pop.update.UpdatePopup;
import com.zhipu.resetbalance.utils.EditionUtils;
import com.zhipu.resetbalance.utils.InitializeUtils;

public class PopupUtils {


    /**
     * 等待提示
     */
    private static BeCommonPopup mBeCommonPopup;

    /**
     * 显示
     */
    public static void showBeCommonPopup(Context mContext){
        mBeCommonPopup = new BeCommonPopup(mContext);
        new XPopup
                .Builder(mContext)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .autoOpenSoftInput(false)
                .asCustom(mBeCommonPopup)
                .show();
    }


    /**
     * 设置内容
     * @param SettingsContent
     */
    public static void SettingBeCommonPopup(String SettingsContent){
        if(null != mBeCommonPopup){
            mBeCommonPopup.setElevatingLanguage(SettingsContent);
        }
    }

    /**
     * 关闭弹框
     */
    public static void dismissAwaitTipsPopup(){
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(null != mBeCommonPopup){
                    mBeCommonPopup.dismiss();
                }
            }
        });
    }









    /**
     * 更新弹框
     */
    private static UpdatePopup mUpdatePopup;

    public static void showAccordingToUpdate(VersionUpdate mVersionUpdate){
        //获取 App 版本码
        int mAppVersionCode = AppUtils.getAppVersionCode();
        if (mVersionUpdate.versionCode > mAppVersionCode) {
            mUpdatePopup = new UpdatePopup(ActivityUtils.getTopActivity(),mVersionUpdate);
            new XPopup.Builder(ActivityUtils.getTopActivity())
                    .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                    .asCustom(mUpdatePopup)
                    .show();
        }else{
            InitializeUtils.getDefaultMaker().show("已经是最新版本!");
        }
    }

    /**
     * 关闭dismiss
     */
    public static void dismissUpdate(){
        if(null != mUpdatePopup){
            mUpdatePopup.dismiss();
        }
    }

}
